<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>知识库<small>膳食库</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>知识库</el-breadcrumb-item>
            <el-breadcrumb-item>膳食库</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <el-input placeholder="食品名称" v-model.trim="pagination.queryString" style="width: 200px;"
                          class="filter-item"></el-input>
                <el-button icon="el-icon-search" @click="findPage()" class="dalfBut">查询</el-button>
                <el-button icon="el-icon-news" type="primary" class="butT" @click="handleCreate()">新建</el-button>
            </div>

                <!--`id``name``exception_type``is_occupational_disease``gender``go_hospital_date``department`
                `level``other_name``medical_interpretation``caused_by``advise`-->
            <el-table size="small" current-row-key="id" :data="dataList" stripe  highlight-current-row>
                <!--<el-table-column type="index" align="center" label="序号"></el-table-column>-->
                <el-table-column type="index" align="center" label="序号"></el-table-column>

                <!--<el-table-column prop="id" label="编码" align="center"></el-table-column>-->
                <el-table-column prop="name" label="食品名称" align="center"></el-table-column>
                <el-table-column  prop="type" label="所属类型" align="center">

                    <template slot-scope="scope">
                        <span v-if="scope.row.type == 1">谷薯类及杂豆</span>
                        <span v-if="scope.row.type == 2">大豆类</span>
                        <span v-if="scope.row.type == 3">蔬菜类</span>
                        <span v-if="scope.row.type == 4">水果类</span>
                        <span v-if="scope.row.type == 5">坚果/种子类</span>
                        <span v-if="scope.row.type == 6">畜肉禽肉鱼虾扇贝类</span>
                        <span v-if="scope.row.type == 7">奶类</span>
                        <span v-if="scope.row.type == 8">蛋类</span>
                    </template>
                </el-table-column>


                <el-table-column  prop="Kcal" label="每Kcal能量" align="center"></el-table-column>

                <el-table-column prop="Protein_content" label="蛋白质含量" align="center"></el-table-column>
                <el-table-column prop="fat_content" label="脂肪含量" align="center"></el-table-column>
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <el-button  icon="el-icon-edit" type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>
                        <el-button  icon="el-icon-delete"  icon="el-icon-delete" size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>


                <!--`id``name``exception_type``is_occupational_disease``gender``go_hospital_date``department`
                `level``other_name``medical_interpretation``caused_by``advise`-->
            <!-- 新增标签弹层 -->
            <div class="add-form">
                <el-dialog title="新增" :visible.sync="dialogFormVisible">
                    <el-form ref="dataAddForm" :model="formData" :rules="rules" label-position="right"
                             label-width="100px">
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="食品名称" prop="name">
                                    <el-input v-model.trim="formData.name"/>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="所属类型" prop="type">
                                    <el-select clearable v-model="formData.type">
                                        <el-option label="谷薯类及杂豆" value="1"></el-option>
                                        <el-option label="大豆类" value="2"></el-option>
                                        <el-option label="蔬菜类" value="3"></el-option>
                                        <el-option label="水果类" value="4"></el-option>
                                        <el-option label="坚果/种子类" value="5"></el-option>
                                        <el-option label="畜肉禽肉鱼虾扇贝类" value="6"></el-option>
                                        <el-option label="奶类" value="7"></el-option>
                                        <el-option label="蛋类" value="8"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                        </el-row>


                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="每Kcal能量" prop="Kcal">
                                    <el-input v-model.trim="formData.Kcal" autosize type="textarea"></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="每KJ能量" prop="Kj">
                                    <el-input v-model.trim="formData.Kj" autosize type="textarea"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>


                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="碳水化合物含量" prop="carbohydrate">
                                    <el-input v-model.trim="formData.carbohydrate" autosize type="textarea"></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="脂肪含量" prop="fat_content">
                                    <el-input v-model.trim="formData.fat_content" autosize type="textarea"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
    <!--`id``name``exception_type``is_occupational_disease``gender``go_hospital_date``department`
                     `level``other_name``medical_interpretation``caused_by``advise`-->
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="蛋白质含量" prop="Protein_content">
                                    <el-input v-model.trim="formData.Protein_content"autosize type="textarea"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>

                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="高血压" prop="hyperpietic">
                                    <el-select clearable v-model="formData.hyperpietic">
                                        <el-option label="是" value="0"></el-option>
                                        <el-option label="否" value="1"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="糖尿病" prop="diabetic">
                                    <el-select clearable v-model="formData.diabetic">
                                        <el-option label="是" value="0"></el-option>
                                        <el-option label="否" value="1"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                        </el-row>

                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="冠心病" prop="coronary_disease">
                                    <el-select clearable v-model="formData.coronary_disease">
                                        <el-option label="是" value="0"></el-option>
                                        <el-option label="否" value="1"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="脑卒中" prop="stroke">
                                    <el-select clearable v-model="formData.stroke">
                                        <el-option label="是" value="0"></el-option>
                                        <el-option label="否" value="1"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                        </el-row>

                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="心脑血管疾病" prop="angiocardiopathy">
                                    <el-select clearable v-model="formData.angiocardiopathy">
                                        <el-option label="是" value="0"></el-option>
                                        <el-option label="否" value="1"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="高血脂" prop="hyperlipidemia">
                                    <el-select clearable v-model="formData.hyperlipidemia">
                                        <el-option label="是" value="0"></el-option>
                                        <el-option label="否" value="1"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                        </el-row>

                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="肥胖" prop="fat">
                                    <el-select clearable v-model="formData.fat">
                                        <el-option label="是" value="0"></el-option>
                                        <el-option label="否" value="1"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="痛风" prop="podagra">
                                    <el-select clearable v-model="formData.podagra">
                                        <el-option label="是" value="0"></el-option>
                                        <el-option label="否" value="1"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                        </el-row>

                        <el-row>
                            <el-col :span="24">
                                <el-form-item label="说明" prop="remark">
                                    <el-input v-model.trim="formData.remark"autosize type="textarea"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>

                    </el-form>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible = false" icon="el-icon-close">取消</el-button>
                        <el-button type="primary" @click="handleAdd()" icon="el-icon-check" icon="el-icon-check" icon="el-icon-check" icon="el-icon-check">确定</el-button>
                    </div>
                </el-dialog>
            </div>

            <!-- 编辑标签弹层 -->
            <div class="add-form">
                <el-dialog title="编辑" :visible.sync="dialogFormVisible4Edit">
                    <el-form ref="dataEditForm" :model="formData" :rules="rules" label-position="right"
                             label-width="100px">
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="食品名称" prop="name">
                                    <el-input v-model.trim="formData.name"/>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="所属类型" prop="type">
                                    <el-select clearable v-model="formData.type">
                                        <el-option label="谷薯类及杂豆" :value="1"></el-option>
                                        <el-option label="大豆类" :value="2"></el-option>
                                        <el-option label="蔬菜类" :value="3"></el-option>
                                        <el-option label="水果类" :value="4"></el-option>
                                        <el-option label="坚果/种子类" :value="5"></el-option>
                                        <el-option label="畜肉禽肉鱼虾扇贝类" :value="6"></el-option>
                                        <el-option label="奶类" :value="7"></el-option>
                                        <el-option label="蛋类" :value="8"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                        </el-row>


                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="每Kcal能量" prop="Kcal">
                                    <el-input v-model.trim="formData.Kcal"autosize type="textarea"></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="每KJ能量" prop="Kj">
                                    <el-input v-model.trim="formData.Kj"autosize type="textarea"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>


                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="碳水化合物含量" prop="carbohydrate">
                                    <el-input v-model.trim="formData.carbohydrate"autosize type="textarea"></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="脂肪含量" prop="fat_content">
                                    <el-input v-model.trim="formData.fat_content"autosize type="textarea"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <!--`id``name``exception_type``is_occupational_disease``gender``go_hospital_date``department`
                                         `level``other_name``medical_interpretation``caused_by``advise`-->
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="蛋白质含量" prop="Protein_content">
                                    <el-input v-model.trim="formData.Protein_content"autosize type="textarea"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>

                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="高血压" prop="hyperpietic">
                                    <el-select clearable v-model="formData.hyperpietic">
                                        <el-option label="是" :value="0"></el-option>
                                        <el-option label="否" :value="1"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="糖尿病" prop="diabetic">
                                    <el-select clearable v-model="formData.diabetic">
                                        <el-option label="是" :value="0"></el-option>
                                        <el-option label="否" :value="1"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                        </el-row>

                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="冠心病" prop="coronary_disease">
                                    <el-select clearable v-model="formData.coronary_disease">
                                        <el-option label="是" :value="0"></el-option>
                                        <el-option label="否" :value="1"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="脑卒中" prop="stroke">
                                    <el-select clearable v-model="formData.stroke">
                                        <el-option label="是" :value="0"></el-option>
                                        <el-option label="否" :value="1"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                        </el-row>

                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="心脑血管疾病" prop="angiocardiopathy">
                                    <el-select clearable v-model="formData.angiocardiopathy">
                                        <el-option label="是" :value="0"></el-option>
                                        <el-option label="否" :value="1"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="高血脂" prop="hyperlipidemia">
                                    <el-select clearable v-model="formData.hyperlipidemia">
                                        <el-option label="是" :value="0"></el-option>
                                        <el-option label="否" :value="1"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                        </el-row>

                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="肥胖" prop="fat">
                                    <el-select clearable v-model="formData.fat">
                                        <el-option label="是" :value="0"></el-option>
                                        <el-option label="否" :value="1"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="痛风" prop="podagra">
                                    <el-select clearable v-model="formData.podagra">
                                        <el-option label="是" :value="0"></el-option>
                                        <el-option label="否" :value="1"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                        </el-row>

                        <el-row>
                            <el-col :span="24">
                                <el-form-item label="说明" prop="remark">
                                    <el-input v-model.trim="formData.remark"autosize type="textarea"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>

                    </el-form>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible4Edit = false" icon="el-icon-close">取消</el-button>
                        <el-button type="primary" @click="handleEdit()" icon="el-icon-check" >确定</el-button>
                    </div>
                </el-dialog>
            </div>
        </div>
    </div>
</div>
</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script>
    var vue = new Vue({
        el: '#app',
        data: {
            pagination: {//分页相关模型数据
                currentPage: 1,//当前页码
                pageSize: 10,//每页显示的记录数
                total: 0,//总记录数
                queryString: null,//查询条件
            },
            dataList: [],//当前页要展示的分页列表数据
            formData: {},//表单数据
            dialogFormVisible: false,//增加表单是否可见
            dialogFormVisible4Edit: false,//编辑表单是否可见
            /*rules: {//校验规则
                code: [{required: true, message: '编码为必填项', trigger: 'blur'}],
                name: [{required: true, message: '疾病名称为必填项', trigger: 'blur'}],
                sex: [{required: true, message: '性别为必填项', trigger: 'blur'}],
                age: [{required: true, message: '适用年龄为必填项', trigger: 'blur'}],
                type: [{required: true, message: '类型为必填项', trigger: 'blur'}],
                price: [{required: true, message: '价格为必填项', trigger: 'blur'}],
                remark: [{required: true, message: '项目说明为必填项', trigger: 'blur'}],
                attention: [{required: true, message: '注意事项为必填项', trigger: 'blur'}]
            }*/


        },
        //钩子函数，VUE对象初始化完成后自动执行
        created() {
            this.findPage();
        },
        methods: {
            //编辑
            handleEdit() {
                this.$refs['dataEditForm'].validate((valid) => {
                    if (valid) {
                        console.log(this.formData);
                        axios.post("/mealsLibrary/update.do", this.formData).then((response) => {
                            //判断后台返回的flag值，true表示编辑操作成功，false为编辑操作失败
                            if (response.data.flag
                            ) {
                                this.$message({
                                    message: response.data.message,
                                    type: 'success'
                                })
                            } else {
                                this.$message.error(response.data.message);
                            }
                        }).finally(() => {
                            //隐藏编辑窗口
                            this.dialogFormVisible4Edit = false;
                            //调用分页查询方法
                            this.findPage();
                        })
                    } else {
                        this.$message.error("数据校验失败，请按规则填写");
                        return false;
                    }
                })
            },
            //添加
            handleAdd() {
                this.$refs['dataAddForm'].validate((valid) => {
                    if (valid) {
                        axios.post("/mealsLibrary/add.do", this.formData).then((response) => {
                            //判断后台返回的flag值，true表示添加操作成功，false为添加操作失败
                            if (response.data.flag
                            ) {
                                this.$message({
                                    message: response.data.message,
                                    type: 'success'
                                })
                            } else {
                                this.$message.error(response.data.message);
                            }
                        }).finally(() => {
                            //隐藏新增窗口
                            this.dialogFormVisible = false;
                            //调用分页查询方法
                            this.findPage();
                        })
                    } else {
                        this.$message.error("数据校验失败，请按规则填写");
                        return false;
                    }
                })
            },
            //分页查询
            findPage() {
                //分页查询的参数
                var temple = this.pagination.queryString;
                var param = {
                    currentPage: this.pagination.currentPage,
                    pageSize: this.pagination.pageSize,
                    queryString: (temple != null && temple === "") ? null : temple
                };
                if (param.queryString != null) {
                    param.currentPage = 1;
                }
                //异步进行分页查询
                axios.post("/mealsLibrary/findPage.do", param).then((res) => {
                    //将分页查询的结果绑定到页面中
                    this.dataList = res.data.rows;
                    this.pagination.total = res.data.total;
                })
                ;
            },
            // 重置表单
            resetForm() {
                //重置表单数据
                this.formData = {};
            },
            // 弹出添加窗口
            handleCreate() {
                //重置添加窗口内容
                this.resetForm();
                //设置添加窗口可见
                this.dialogFormVisible = true;
            },
            // 弹出编辑窗口
            handleUpdate(row) {
                //修改编辑表单数据为选中行数据
                this.formData = row;
                //修改编辑表单可见性
                this.dialogFormVisible4Edit = true;
            },
            //切换页码
            handleCurrentChange(currentPage) {
                //使用临时变量存储搜索框中数据
                var queryString = this.pagination.queryString;
                //修改搜索框中的数据为null
                this.pagination.queryString = null;
                //修改分页查询页码为选中页码
                this.pagination.currentPage = currentPage;
                //调用分页查询
                this.findPage();
                //将搜索框中数据重写回搜索框
                this.pagination.queryString = queryString;
            },
            // 删除
            handleDelete(row) {
                this.$confirm('此操作将删除条数据, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    axios.get("/mealsLibrary/delete/" + row.id + ".do").then((res) => {
                        if (res.data.flag
                        ) {
                            this.$message({
                                message: res.data.message,
                                type: 'success'
                            });
                        } else {
                            alert("删除失败！")
                            this.$message.error(res.data.message);
                            return false;
                        }
                    }).finally(() => {
                            this.findPage();
                        }
                    )
                    ;
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '操作已取消'
                    });
                })
                ;
            }
        }
    })
</script>
</html>